<?php

class Emms_Form_Admin_BusinessType extends HTech_Form
{
    protected $_primary  = 'TypeId';
    
    public function __construct() 
    {
        parent::__construct();
        
        $this->setName('BusinessType');
        
        $this->setAttrib('title', $this->translate("Business type form"));
        $this->setDescription($this->translate("Edit business type info or add a new one"));
        
        $typeId = new Zend_Form_Element_Hidden('TypeId');
        
        $activity = new Zend_Form_Element_Select('Activity');
        $activity->setLabel("Activity")                
            ->setAttrib('size','4')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions(
                array(
                    'Service' => $this->translate("Service"), 
                    'Industry' => $this->translate("Industry"),
                    'Commerce' => $this->translate("Commerce"), 
                    'Farm' => $this->translate("Farm")));
        
        $type = new Zend_Form_Element_Text('Type');
        $type->setLabel("Business type")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Alpha', array('allowwhitespace' => true))
            ->addValidator('StringLength',false,
                array(
                    'min'      => 3,
                    'max'      => 128,
                    'messages' => $this->translate("From %min% to %max% characters only")
                ))
            ->addValidator('Db_NoRecordExists',false,
                array(
                    'table'    => 'business_types', 
                    'field'    => 'Type', 
                    'exclude'  => array('field' => 'TypeId', 'value' => $this->_id),
                    'messages' => $this->translate("Non valid or duplicated entry")                    
                ))
            ->setDescription(null);  
        
        $description = new Zend_Form_Element_Textarea('Description');
        $description->setLabel("Description")
            ->addFilter('Alnum', array('allowwhitespace' => true))
            ->setAttrib('rows', 4); 
        
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type'=>'submit')));
        
        $this->addElements(array($type,$activity,$description,$submit,$typeId));
    }
}